/* 
 * File:   DocTerms.h
 * Author: eduardo
 *
 * Created on 31 de octubre de 2012, 20:31
 */

#include "DocTerms.h"
#include "Utilities.h"
#include <cstdlib>
#include <iostream>

DocTerms::DocTerms() {
}

DocTerms::~DocTerms() {
    _terms.clear();
}

void DocTerms::insert(string cad) {
    cad = Utilities::toLower(cad);
    map<string, int>::iterator it = _terms.find(cad);
    if (it != _terms.end()) {
        // La cadena pertenece a la ed
        (*it).second++;
    } else {
        _terms.insert(pair<string, int>(cad, 1));
    }
}

bool DocTerms::belong(string cad) {
    return _terms.find(Utilities::toLower(cad)) != _terms.end();
}

int DocTerms::getSize() {
    return _terms.size();
}

int DocTerms::termCount(const string& term) {
    int count = 0;
    string cad = Utilities::toLower(term);
    if (belong(cad)) {
        count = _terms.at(cad);
    }
    return count;
}